package com.customization.api.e9sso.cmd;



import com.customization.api.e9sso.biz.CusRequestDetailImport;
import com.customization.commons.Console;
import com.engine.core.interceptor.AbstractCommand;
import com.engine.core.interceptor.CommandContext;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;

import org.apache.tools.ant.taskdefs.Concat;
import weaver.file.FileUpload;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;
import weaver.workflow.request.RequestDetailImport;

public class CusRequestDetailImportCmd extends AbstractCommand<Map<String, Object>> {
    private HttpServletRequest request;

    public CusRequestDetailImportCmd(HttpServletRequest var1, User var2) {
        this.request = var1;
        this.user = var2;
    }

    public Map<String, Object> execute(CommandContext var1) {
        HashMap var2 = new HashMap();
        FileUpload fu = new FileUpload(this.request);


        String uploadFiles="";
        try{
             uploadFiles = Util.null2String(fu.uploadFiles("excelfile"));
             Console.log("uploadFiles:"+uploadFiles);
             Console.log("所有参数:"+getParamsFromFormDataByNames(this.request).toString());
        }catch (Exception  e){
            Console.log("uploadFiles报错:"+e.toString());
        }
        String var4 = Util.null2String(fu.getParameter("src"));
        int var5 = Util.getIntValue(fu.getParameter("requestid"));

        if(!uploadFiles.equals("")){
                if (var4.equals("save") && var5 != -1) {
                    var2.put("noRight", false);
                    try {

                        String var6 = Util.null2String((new CusRequestDetailImport()).ImportDetail(fu, this.user));
                        if ("".equals(var6)) {
                            var6 = SystemEnv.getHtmlLabelName(25750, this.user.getLanguage());
                        }

                        var2.put("message", var6);
                    } catch (Exception e) {
                        e.printStackTrace();
                        var2.put("Exception", e.toString());
                    }
                } else {
                    var2.put("noRight", true);
                }
        }

        return var2;
    }

    public HttpServletRequest getRequest() {
        return this.request;
    }

    public void setRequest(HttpServletRequest var1) {
        this.request = var1;
    }

    public Map<String, String> getParamsFromFormDataByNames(HttpServletRequest request){
        Map<String, String> map =new HashMap<>();
        Enumeration<String> er = request.getParameterNames();
        while (er.hasMoreElements()) {
            String name = (String) er.nextElement();
            String value = request.getParameter(name);
            map.put(name, value);
        }
        return map;
    }
}
